#pragma once


namespace mylist
{
	template<class T>
	struct list_node
	{
		list_node<T>* _next;
		list_node<T>* _prev;
		T _val;

		list_node(const T& val = T())
			:_next(nullptr)
			,_prev(nullptr)
			,_val(val)
		{}
	};

	template<class T>
	struct _list_iterator
	{
		typedef list_node<T> Node;
		Node* _node;

		_list_iterator(Node* node)
			:_node(node)
		{}

		T& operator*()
		{
			
			return _node->_val;
		}
		
		_list_iterator operator++()
		{
			_node =  _node->_next;
			return *this;
		}
		bool operator!=(const _list_iterator<T>& it)
		{
			return _node != it._node;
		}
	};

	template<class T>

	class list
	{
		typedef list_node<T> Node;

	public:
		typedef _list_iterator<T> iterator;

		iterator begin()
		{
			return _head->_next;
		}
		iterator end()
		{
			return _head;
		}

		list()
		{
			_head = new Node;
			_head->_next = _head;
			_head->_prev = _head;
		}

		void push_back(const T& x)
		{

			Node* newcode = new Node(x);
			Node* tail = _head->_prev;

			tail->_next = newcode;
			newcode->_prev = tail;

			newcode->_next = _head;
			_head->_prev = newcode;
		}

	private:

		Node* _head;
	};
}

